//
//  DiaoDuEditCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/8/19.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "DiaoDuEditCell.h"
#import "SupplierMainModel.h"

@interface DiaoDuEditCell ()

@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *typeLab;
@property (nonatomic, strong) UILabel *contentLab;
@property (nonatomic, strong) UILabel *lineLab;
@property (nonatomic, strong) UIButton *operationBtn;

@end

@implementation DiaoDuEditCell

+ (instancetype)DiaoDuEditCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"DiaoDuEditCell";
    DiaoDuEditCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[DiaoDuEditCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = HexColor(0xffffff);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.nameLab = [UILabel new];
        self.nameLab.textColor = HexColor(0x2B2C44);
        self.nameLab.font = BoldFontOfSize(18);
        [self.contentView addSubview:self.nameLab];
        
        self.typeLab = [UILabel new];
        self.typeLab.textColor = Color_ThemeColor;
        self.typeLab.font = BoldFontOfSize(12);
        self.typeLab.backgroundColor = HexColorA(0x3D68EB, 0.1);
        self.typeLab.layer.masksToBounds = YES;
        self.typeLab.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.typeLab];
        
        self.contentLab = [UILabel new];
        self.contentLab.textColor = HexColor(0x9C9DB3);
        self.contentLab.font = [UIFont systemFontOfSize:14];
        self.contentLab.numberOfLines = 0;
        [self.contentView addSubview:self.contentLab];
        
        self.lineLab = [UILabel new];
        self.lineLab.backgroundColor = HexColor(0xF2F2F5);
        [self.contentView addSubview:self.lineLab];
        
        self.operationBtn = [UIButton new];
        [self.operationBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.operationBtn];
    }
    return self;
}

- (void)btnClick {
    if (self.chooseBlock) {
        self.chooseBlock();
    }
}

-(void)setModel:(CarMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.nameLab.nim_left = 58;
    self.nameLab.nim_top = 20;
    self.nameLab.text = self.model.num;
    [self.nameLab sizeToFit];
    
    self.typeLab.text = self.model.car_type;
    [self.typeLab sizeToFit];
    self.typeLab.nim_width += 24;
    self.typeLab.nim_height = 22;
    self.typeLab.nim_left = self.nameLab.nim_right + 10;
    self.typeLab.nim_centerY = self.nameLab.nim_centerY;
    self.typeLab.layer.cornerRadius = 11;
    
    if (self.model.tpls.length) {
        self.contentLab.nim_left = self.nameLab.nim_left;
        self.contentLab.nim_top = self.nameLab.nim_bottom + 8;
        self.contentLab.text = self.model.tpls;
        self.contentLab.nim_width = ScreenW - self.contentLab.nim_left - 15;
        [self.contentLab sizeToFit];
        
        self.lineLab.frame = CGRectMake(0, self.contentLab.nim_bottom + 19, ScreenW, 1);
    }else {
        self.contentLab.frame = CGRectZero;
        self.lineLab.frame = CGRectMake(0, self.nameLab.nim_bottom + 19, ScreenW, 1);
    }
    
    self.height = self.lineLab.nim_bottom;
    
    self.operationBtn.nim_width = 23;
    self.operationBtn.nim_height = 23;
    self.operationBtn.nim_left = 15;
    self.operationBtn.nim_top = (self.height - self.operationBtn.nim_height) * 0.5;
    if (self.model.isSelected) {
        [self.operationBtn setImage:[UIImage imageNamed:@"icon_backBox_choice_sel"] forState:0];
    }else {
        [self.operationBtn setImage:[UIImage imageNamed:@"icon_backBox_choice"] forState:0];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
